package org.cangku.controller;

import org.cangku.dao.XsLinShiDao;
import org.cangku.entity.Xslinshi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/xsls")
public class XsLinShiController {
    @Autowired
    private XsLinShiDao xsLinShiDao;
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String,Object> insert(String danhao,int bh,String mc,int bid,String cm,String ys,int fid,int num,double dj,double money){
        Map<String,Object> map = new HashMap<String, Object>();

        Xslinshi ls = new Xslinshi();
       ls.setXsdanhao(danhao);
       ls.setXssid(bh);
       ls.setXsname(mc);
       ls.setXspinp(bid);
       ls.setXssize(cm);
       ls.setXsyanse(ys);
       ls.setXsfenlei(fid);
       ls.setXsnum(num);
       ls.setXsdj(dj);
       ls.setXszongjia(money);
        int i = xsLinShiDao.extendInfo(ls);
        if(i>0){
            xsLinShiDao.updateNumAndzMoney(ls);
        }else{
            xsLinShiDao.insert(ls);
        }

        map.put("xslist",xsLinShiDao.query());
        map.put("zongmoney",xsLinShiDao.getZongMoney());
        return map;
    }

    /*刷新页面清空所有 要购买的商品*/
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> delete(){
        Map<String,Object> map = new HashMap<String, Object>();
        int i =xsLinShiDao.delete();
        if(i>0){
            map.put("row",i);
            //map.put("list",xsLinShiDao.query());
        }else{
            map.put("row",0);
        }
        return map;
    }

    /*单个删除*/
    @RequestMapping("/onedelete")
    @ResponseBody
    public Map<String,Object> onedelete(String dingdan,int id,String size){
        System.out.println(dingdan);
        Map<String,Object> map = new HashMap<String, Object>();
        int i = xsLinShiDao.onedelete(dingdan,id,size);
        if(i>0){
            map.put("zai",1);
            map.put("qian",xsLinShiDao.getZongMoney());
            map.put("list",xsLinShiDao.query());
        }

        return map;
    }
}
